<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form-model ref="formRef">
        <a-row>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="mainNo"
                ><a-input v-model="queryParam.mainNo" placeholder="请输入盘点任务号" allowClear />
              </a-form-model-item>
            </div>
          </a-col>

          <a-col :span="8">
            <div style="margin-top: 4px">
              <a-button style="margin-right: 20px" @click="searchQuery()" type="primary"> 查询 </a-button>
              <a-button style="margin-right: 20px" @click="addOrder()" type="primary"> 创建盘点任务 </a-button>
              <a-button style="margin-right: 20px" @click="searchReset()"> 重置 </a-button>
            </div>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button type="primary" icon="download" @click="handleExport1()">导出全部</a-button> -->
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="blState" slot-scope="text, record">
          <span>{{ getBlState(text.blState) }}</span>
        </template>
        <!-- 槽 渲染 指定 cloumn的值 -->
        <template slot="state" slot-scope="text, record">
          <a-tag :color="onColor(text.state)">
            {{ getOrderState(text.state) }}
          </a-tag>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleExport(record)">导出</a>
        </span>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { addcheckTaskApi } from '@/api/warehouse'

export default {
  name: 'YkCodeList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    //   YkCodeModal,
  },
  data() {
    return {
      // description: 'wms_bar_bind_order管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '所属公司',
          align: 'center',
          dataIndex: 'company',
        },
        {
          title: '盘点任务号',
          align: 'center',
          dataIndex: 'mainNo',
        },

        {
          title: '状态',
          align: 'center',
          scopedSlots: { customRender: 'state' },
        },

        {
          title: '开始日期',
          align: 'center',
          dataIndex: 'startTime',
        },

        {
          title: '结束日期',
          align: 'center',
          dataIndex: 'endTime',
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/wms/wmsCheckMain/list',
        delete: '/wms/wmsCheckMain/delete',
        deleteBatch: '/wms/wmsCheckMain/deleteBatch',
        exportXlsUrl: '/wms/wmsCheckMain/exportXls',
        importExcelUrl: 'wms/wmsCheckMain/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    getOrderState(state) {
      if (state === '0') {
        return '开始'
      } else {
        return '结束'
      }
    },

    // 状态颜色
    onColor(text) {
      let color = ''
      if (text == 0) color = 'green'
      if (text == 1) color = 'red'
      return color
    },

    async addOrder() {
      const r = await addcheckTaskApi({})
      this.loadData()
    },

    handleExport(e) {
      // console.log('handleExport', e)
      this.handleExportXls('一品一码绑定_' + e.orderNo, { id: e.id, field: '' })
    },
    handleExport1(e) {
      this.handleExportXls('一品一码绑定')
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'orderNo', text: '订单号' })
      fieldList.push({ type: 'string', value: 'orderType', text: '订单类型' })
      fieldList.push({ type: 'string', value: 'state', text: '状态' })
      fieldList.push({ type: 'int', value: 'sums', text: '数量' })
      fieldList.push({ type: 'int', value: 'createBy', text: '创建人' })
      fieldList.push({ type: 'string', value: 'createTime', text: '公司' })
      fieldList.push({ type: 'string', value: 'warehourse', text: '所属仓库' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
